//
//  RecordTableViewCell.m
//  兼职页面
//
//  Created by kuiyuan liang on 2021/5/29.
//

#import "RecordTableViewCell.h"
#import "CommonUtil.h"

@interface RecordTableViewCell()
@property (strong, nonatomic) UIView * whiteView;
@property (strong, nonatomic) UIImageView * iconImageView;
@property (strong, nonatomic) UILabel * nameLabel;

@property (strong, nonatomic) UILabel * typeLabel;
@property (strong, nonatomic) UILabel * typeValueLabel;

@property (strong, nonatomic) UILabel * startLabel;
@property (strong, nonatomic) UILabel * startValueLabel;

@property (strong, nonatomic) UILabel * mubiaoLabel;
@property (strong, nonatomic) UILabel * mubiaoValueLabel;

@property (strong, nonatomic) UILabel * currentLabel;
@property (strong, nonatomic) UILabel * currentValueLabel;

@property (strong, nonatomic) UIButton * doneBtn;
@property (strong, nonatomic) UIButton * challengeBtn;

@property (strong, nonatomic) UIImageView * iconImageView2;
@property (strong, nonatomic) UILabel * moneyLabel;

@property (strong, nonatomic) UIImageView * statusImageView;
@end

@implementation RecordTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor clearColor];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.whiteView];
        [self.whiteView addSubview:self.iconImageView];
        [self.whiteView addSubview:self.nameLabel];
        
        [self.whiteView addSubview:self.typeLabel];
        [self.whiteView addSubview:self.typeValueLabel];
        
        [self.whiteView addSubview:self.startLabel];
        [self.whiteView addSubview:self.startValueLabel];
        
        [self.whiteView addSubview:self.mubiaoLabel];
        [self.whiteView addSubview:self.mubiaoValueLabel];
        
        [self.whiteView addSubview:self.currentLabel];
        [self.whiteView addSubview:self.currentValueLabel];
        
        [self.whiteView addSubview:self.doneBtn];
        [self.whiteView addSubview:self.challengeBtn];
        
        [self.whiteView addSubview:self.iconImageView2];
        [self.whiteView addSubview:self.moneyLabel];
        [self.whiteView addSubview:self.statusImageView];
    }
    return self;
}

- (void)btnClick:(UIButton *)sender{
    NSLog(@"%@",sender.titleLabel.text);
    if (self.block) {
        self.block(sender.titleLabel.text);
    }
}


-(UIView *)whiteView{
    if (!_whiteView) {
        _whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, AD(260))];
        _whiteView.backgroundColor = [UIColor whiteColor];
        _whiteView.layer.cornerRadius= AD(5);
    }
    return _whiteView;
}

-(UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"statistics_default.jpg"]];
        _iconImageView.frame = CGRectMake(AD(15), AD(15), AD(70), AD(70));
        _iconImageView.layer.cornerRadius = AD(35);
        _iconImageView.clipsToBounds = YES;
    }
    return _iconImageView;
}

-(UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(_iconImageView.right + AD(10), 0, AD(200), AD(30))];
        _nameLabel.text = @"合家欢喜";
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = [UIFont systemFontOfSize:AD(15)];
        _nameLabel.centerY = self.iconImageView.centerY;
    }
    return _nameLabel;
}

-(UILabel *)typeLabel{
    if (!_typeLabel) {
        _typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(15), _iconImageView.bottom, 0, AD(30))];
        _typeLabel.text = @"类型:";
        _typeLabel.textColor = [UIColor blackColor];
        _typeLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _typeLabel.width = [CommonUtil countWidth:_typeLabel.text font:_typeLabel.font height:_typeLabel.height];
    }
    return _typeLabel;
}
-(UILabel *)typeValueLabel{
    if (!_typeValueLabel) {
        _typeValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_typeLabel.right + AD(3), _typeLabel.top, AD(200), AD(30))];
        _typeValueLabel.text = @"三肖";
        _typeValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _typeValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _typeValueLabel;
}

-(UILabel *)startLabel{
    if (!_startLabel) {
        _startLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(15), _typeLabel.bottom, 0, AD(30))];
        _startLabel.text = @"起始期数:";
        _startLabel.textColor = [UIColor blackColor];
        _startLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _startLabel.width = [CommonUtil countWidth:_startLabel.text font:_startLabel.font height:_startLabel.height];
    }
    return _startLabel;
}
-(UILabel *)startValueLabel{
    if (!_startValueLabel) {
        _startValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_startLabel.right + AD(3), _typeLabel.bottom, AD(200), AD(30))];
        _startValueLabel.text = @"20211037期";
        _startValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _startValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _startValueLabel;
}

-(UILabel *)mubiaoLabel{
    if (!_mubiaoLabel) {
        _mubiaoLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(15), _startLabel.bottom, 0, AD(30))];
        _mubiaoLabel.text = @"目标:";
        _mubiaoLabel.textColor = [UIColor blackColor];
        _mubiaoLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _mubiaoLabel.width = [CommonUtil countWidth:_mubiaoLabel.text font:_mubiaoLabel.font height:_mubiaoLabel.height];
    }
    return _mubiaoLabel;
}
-(UILabel *)mubiaoValueLabel{
    if (!_mubiaoValueLabel) {
        _mubiaoValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_mubiaoLabel.right + AD(3), _startLabel.bottom, AD(200), AD(30))];
        _mubiaoValueLabel.text = @"0 对 0 以 上";
        _mubiaoValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _mubiaoValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _mubiaoValueLabel;
}

-(UILabel *)currentLabel{
    if (!_currentLabel) {
        _currentLabel = [[UILabel alloc] initWithFrame:CGRectMake(AD(15), _mubiaoLabel.bottom, 0, AD(30))];
        _currentLabel.text = @"当前:";
        _currentLabel.textColor = [UIColor blackColor];
        _currentLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _currentLabel.width = [CommonUtil countWidth:_currentLabel.text font:_currentLabel.font height:_currentLabel.height];
    }
    return _currentLabel;
}
-(UILabel *)currentValueLabel{
    if (!_currentValueLabel) {
        _currentValueLabel = [[UILabel alloc] initWithFrame:CGRectMake(_currentLabel.right + AD(3), _mubiaoLabel.bottom, AD(200), AD(30))];
        _currentValueLabel.text = @"0 对 0";
        _currentValueLabel.textColor = RGB(124.0, 124.0, 124.0);
        _currentValueLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
    }
    return _currentValueLabel;
}

-(UIButton *)doneBtn{
    if (!_doneBtn) {
        _doneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_doneBtn setTitle:@"已完成" forState:UIControlStateNormal];
        [_doneBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _doneBtn.titleLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _doneBtn.layer.cornerRadius = AD(5);
        _doneBtn.backgroundColor = RGB(81.0, 172.0, 211.0);
        CGFloat w = (SCREEN_WIDTH-AD(40))/2;
        _doneBtn.frame = CGRectMake(AD(15), _currentLabel.bottom + AD(5), w, AD(40));
        [_doneBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _doneBtn;
}

-(UIButton *)challengeBtn{
    if (!_challengeBtn) {
        _challengeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_challengeBtn setTitle:@"挑战" forState:UIControlStateNormal];
        [_challengeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _challengeBtn.titleLabel.font = [UIFont boldSystemFontOfSize:AD(15)];
        _challengeBtn.layer.cornerRadius = AD(5);
        _challengeBtn.backgroundColor = RGB(236.0, 92.0, 77.0);
        CGFloat w = (SCREEN_WIDTH-AD(40))/2;
        _challengeBtn.frame = CGRectMake(_doneBtn.right + AD(10), _currentLabel.bottom + AD(5), w, AD(40));
        [_challengeBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _challengeBtn;
}

-(UIImageView *)iconImageView2{
    if (!_iconImageView2) {
        _iconImageView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_money"]];
        _iconImageView2.frame = CGRectMake(SCREEN_WIDTH-AD(100), _mubiaoLabel.top, AD(94*0.6), AD(60*0.6));
    }
    return _iconImageView2;
}
-(UILabel *)moneyLabel{
    if (!_moneyLabel) {
        _moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _iconImageView2.bottom, AD(100), AD(30))];
        _moneyLabel.text = @"获得3元";
        _moneyLabel.textColor = [UIColor blackColor];
        _moneyLabel.font = [UIFont systemFontOfSize:AD(14)];
        _moneyLabel.centerX = _iconImageView2.centerX;
        _moneyLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _moneyLabel;
}

-(UIImageView *)statusImageView{
    if (!_statusImageView) {
        _statusImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
        _statusImageView.frame = CGRectMake(SCREEN_WIDTH-AD(80), _mubiaoLabel.top, AD(50), AD(50));
        _statusImageView.backgroundColor = [UIColor lightGrayColor];
        _statusImageView.centerY = _iconImageView.centerY;
        _statusImageView.layer.cornerRadius = AD(25);
        _statusImageView.clipsToBounds = YES;
    }
    return _statusImageView;
}

@end
